﻿var prog_name = "krj_tracking.js";

function SelectRows() {
    try
    {
        if (!$(".SelectedRow").length > 0) {
            alert('請選取一筆資料!!');
            return false;
        }
        else
            return true;
    }
    catch(err)
    {
        txt = "程式發生錯誤！\n";
        txt+="錯誤訊息: " + err.message + "\n\n";
        txt+="請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "SelectRows", "USER", "js", err);
        return false;
    }

}

function btnSearch_Click(p_PageIndex) {
try
{
    var sType = '';
    var sORDER = '';
    var sFunction = '';
   
    //去空白
    //$("#" + p_TrId + " td").each(function (index) {
    //    m_Param += ((index == 0) ? "" : ",") + "" + m_ColumnsNames[index].id.replace("th", "") + ":'" + $.trim($(this).text()) + "'";
    //});

    $("input[id*='txt']").each(function () {
       
        this.value = $.trim(this.value);
       
    });

    var message = "";
    //欄位判斷
    if ($("#MainContent_txtCARGO_NO_S").val() != "" && $("#MainContent_txtCARGO_NO_S").val().length != 11)
    {
        alert("託運單號輸入錯誤，請輸入11碼！");
        return false;
    }
    if ($("#MainContent_txtCARGO_NO_S").val() == "" && $("#MainContent_txtDISPATCH_DATE_txtDate").val() == "" && $("#MainContent_txtRECEIVER").val() == "" && $("#MainContent_ddlDISPATCH_DEPT").val() == "" && $("#MainContent_ddlRECEIVE_DEPT").val() == "" && $("#MainContent_txtCUSTOMER").val() == "") {
        alert("請輸入查詢條件！\n 1.託運單號 \n 2.發送日期 + 收貨人 \n 3.發送日期 + 發到所站 + 到著所站 \n 4.發送日期 + 客戶編號 \n 不可皆為空白！");
        return false;
    }
    else {
        if ($("#MainContent_txtCARGO_NO_S").val() == "") {
            if ($("#MainContent_txtDISPATCH_DATE_txtDate").val() != "") {
                if ($("#MainContent_txtRECEIVER").val() == "" && $("#MainContent_ddlDISPATCH_DEPT").val() == "" && $("#MainContent_ddlRECEIVE_DEPT").val() == "" && $("#MainContent_txtCUSTOMER").val() == "") {
                    alert("請輸入查詢條件！\n發送日期與收貨人 或 \n發送日期與發送所站及到著所站 或 \n發送日期與客戶編號 必需同時輸入！");
                    return false;
                }
                else {
                    if ($("#MainContent_ddlDISPATCH_DEPT").val() != "" && $("#MainContent_ddlRECEIVE_DEPT").val() == "") {
                        alert("請輸入查詢條件！\n發送日期與發送所站及到著所站必需同時輸入！");
                        return false;
                    }
                    if ($("#MainContent_ddlDISPATCH_DEPT").val() == "" && $("#MainContent_ddlRECEIVE_DEPT").val() != "") {
                        alert("請輸入查詢條件！\n發送日期與發送所站及到著所站必需同時輸入！");
                        return false;
                    }
                }



            }
            else {
                alert("請輸入查詢條件！\n發送日期與收貨人 或 \n發送日期與發送所站及到著所站 或 \n發送日期與客戶編號 必需同時輸入");
                return false;
            }
        }
        
    }


    //頁次
    var m_PageIndex = getPageIndex(p_PageIndex);

    s_TODAY = 'A';
    sORDER = 'F63103,F63104,F63101,F63102';
    sFunction = "GetDISPATCH";
    //查詢條件 對應後端查詢條件
    //當日配
    var s_TODAY = "";
    if ($("#chkToday")[0].checked) {
        s_TODAY = "Y";
    }

    var StrWhere = { CARGO_NO_S: $("#MainContent_txtCARGO_NO_S").val(), CARGO_NO_E: $("#MainContent_txtCARGO_NO_E").val(), DISPATCH_DATE: $("#MainContent_txtDISPATCH_DATE_txtDate").val(), SHIPPER: $("#MainContent_txtSHIPPER").val(), SHIPPER_NAME: $("#MainContent_txtSHIPPER_NAME").val(), RECEIVER: $("#MainContent_txtRECEIVER").val(), PROJECT: $("#MainContent_txtPROJECT").val(), PAYER: $("#MainContent_txtPAYER").val(), CUSTOMER: $("#MainContent_txtCUSTOMER").val(), DISPATCH_DEPT: $("#MainContent_ddlDISPATCH_DEPT").val(), RECEIVED_DEPT: $("#MainContent_ddlRECEIVE_DEPT").val(), s_TODAY: s_TODAY, sType: 'A' };

    $("#DocumentPageControl").attr("GridWidth", "8%,9%,9%,8%,15%,15%,5%,11%,5%,5%");
    $("#DocumentPageControl").attr("textalign", "C,C,C,C,C,C,C,C,C,C");
    $("#DocumentPageControl").attr("HideColumn", "DETAIL_NO,ITEM_NO,CORRECT_NO,ORG_SHIPPING_NO");

    //組Grid 公用Function 後端網頁名稱, 查詢FUNCTION名稱, 頁次, 一頁筆數, 排序條件, 查詢條件, 目標 DIV
    gdb_DataBind("krj_tracking", sFunction, m_PageIndex, "15", sORDER, StrWhere, "Document");


    $("div[id='Document']").show();
    $("div[id='divPageinfo']").show();
    }
    catch (err) {
        txt = "程式發生錯誤！\n";
        txt += "錯誤訊息: " + err.message + "\n\n";
        txt += "請按確定繼續.\n\n";
        alert(txt);
        save_error(prog_name, "SelectRows", "USER", "js", err);
        return false;
    }
}


function select(clientId) {
    //var date = $get(clientId + "_txtDate").value;
    //var year = parseInt($("#" + clientId + "_txtDate").val().substr(0, 4)) - 1911;
    //$("#" + clientId + "_txtDate").val(year + $("#" + clientId + "_txtDate").val().substr(4, 6))
}